<?php
/**
 * 部件基类
 * @copyright 2020-2021 WillPHP
 * @author NoMind<24203741@qq.com/113344.com>
 * @version WillPHPv3
 * @since 2021-12-01
 */
namespace wiphp;
defined('WIPHP_URI') or die('Access Denied');
abstract class Widget {
	protected $name = 'willphp';
	protected $time = 0;		
	public function getData($id = '', $options = []) {
		$name = $this->parseName($id, $options);
		$data = Cache::get($name);
		if (!$data) {
			$data = $this->setData($id, $options);
			if ($data) {
				Cache::set($name, $data, $this->time);
			}
		}
		return $data;
	}
	public function delData($id = '', $options = []) {
		$name = $this->parseName($id, $options);
		return Cache::del($name);
	}
	protected function parseName($id = '', $options = []) {
		$name = $this->name.$id;
		if (!empty($options)) {
			ksort($options);
			$name .= http_build_query($options);
		}
		return md5($name);		
	}
	abstract public function setData($id = '', $options = []);
}